#ifndef LOADMAP_H
#define LOADMAP_H

#include "QuadTree.h"
#include "Object.h"

#include <map>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;

class Simon;
class LoadMap
{
private:
	LPDIRECT3DDEVICE9	d3ddv;
	LPDIRECT3DSURFACE9	backBuffer;
	LPD3DXSPRITE		spriteHandler;	// SpriteHandler to draw texture

	std::map<int, QNode*> qTree_map;

public:
	//std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);
	//std::vector<std::string> split(const std::string &s, char delim);

	LoadMap(LPDIRECT3DDEVICE9 d3ddv, LPDIRECT3DSURFACE9 backBuffer, LPD3DXSPRITE spriteHandler);

	//read file quad tree
	list<Object*> obj_list;
	list<TilesObject*> tiles_list;
	
	map<int, Object*> obj_map;
	map<int, TilesObject*> tiles_map;

	int numScore;
	int numLife;
	int numCoin;

	int posX_first;		//vi tri mario ban dau
	int posY_first;
	int posX_last;		//vi tri mario khi load map tu map phu tro lai map chinh, vi tri cua pipe
	int posY_last;

	int mario_state;
	int mario_direction;
	int mario_isSmall;	//0: small, 1: big

	bool submapToMap;

	int width_map;

	void loadFileObj(string file_name);					//load file chua obj len list, sau nay add vao quadtree
	void loadFileTiles(string file_name);					//load file chua tiles len list, sau nay add vao quadtree
	void loadFileQuadtreeObjToMap(string file_name);		//load file quadtree obj, build lai thanh cay quadtree obj
	void loadFileQuadtreeTilesToMap(string file_name);	//load file quadtree tiles, build lai thanh cay quadtree tiles
	void deserializeQuadtree(QuadTree *root);
	void buildQuadtree(QNode *n);

	void saveFileObj(char* file_name, list<Object*> obj_list);			//save cac obj xuong file, de load game

	map<int, vector<string>> all_map;
	void LoadAllMap(char* file_name);
	
};

#endif